home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / pppdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-27  |  2.6 KB  |  112 lines

  1. /*
  2.  *    PPPDUMP.C
  3.  *
  4.  *    12-89    -- Katie Stevens (dkstevens@ucdavis.edu)
  5.  *           UC Davis, Computing Services
  6.  *    PPP.08    05-90    [ks] improve tracing reports
  7.  *    PPP.09  05-90    [ks] add UPAP packet reporting
  8.  *    PPP.14    08-90    [ks] change UPAP to PAP for consistency with RFC1172
  9.  *    PPP.15    09-90    [ks] update to KA9Q NOS v900828
  10.  *    Jan 91    [Bill Simpson] small changes to match rewrite of PPP
  11.  *    Aug 91    [Bill Simpson] fixed some buffer loss
  12.  */
  13. #include "global.h"
  14. #ifdef PPP
  15. #include "mbuf.h"
  16. #include "iface.h"
  17. #include "internet.h"
  18. #include "ppp.h"
  19. #include "trace.h"
  20.  
  21. #ifdef TNOS_68K
  22. #define fprintf traceprintf
  23. #endif
  24.  
  25. #ifdef TURBOC_SWITCH_BUG
  26. #pragma option -G-
  27. #endif
  28.  
  29. /* dump a PPP packet */
  30. void
  31. ppp_dump(fp,bpp,unused)
  32. FILE *fp;
  33. struct mbuf **bpp;
  34. int unused;
  35. {
  36.     struct ppp_hdr hdr;
  37.     struct mbuf *tbp;
  38.  
  39.     fprintf(fp,"PPP: len %3u\t", len_p(*bpp));
  40.  
  41.     /* HDLC address and control fields may be compressed out */
  42.     if ((byte_t)(*bpp)->data[0] != HDLC_ALL_ADDR) {
  43.         fprintf(fp,"(compressed ALL/UI)\t");
  44.     } else if ((byte_t)(*bpp)->data[1] != HDLC_UI) {
  45.         fprintf(fp,"(missing UI!)\t");
  46.     } else {
  47.         /* skip address/control fields */
  48.         pull16(bpp);
  49.     }
  50.  
  51.     /* Initialize the expected header */
  52.     hdr.addr = HDLC_ALL_ADDR;
  53.     hdr.control = HDLC_UI;
  54.     hdr.protocol = PULLCHAR(bpp);
  55.  
  56.     /* First byte of PPP protocol field may be compressed out */
  57.     if ( hdr.protocol & 0x01 ) {
  58.         fprintf(fp,"compressed ");
  59.     } else {
  60.         hdr.protocol = (hdr.protocol << 8) | PULLCHAR(bpp);
  61.  
  62.         /* Second byte of PPP protocol field must be odd */
  63.         if ( !(hdr.protocol & 0x01) ) {
  64.             fprintf(fp, "(not odd!) " );
  65.         }
  66.     }
  67.  
  68.     fprintf(fp,"protocol: ");
  69.     switch(hdr.protocol){
  70.         case PPP_IP_PROTOCOL:
  71.             fprintf(fp,"IP\n");
  72.             ip_dump(fp,bpp,1);
  73.             break;
  74.         case PPP_IPCP_PROTOCOL:
  75.             fprintf(fp,"IPCP\n");
  76.             break;
  77.         case PPP_LCP_PROTOCOL:
  78.             fprintf(fp,"LCP\n");
  79.             break;
  80.         case PPP_PAP_PROTOCOL:
  81.             fprintf(fp,"PAP\n");
  82.             break;
  83.         case PPP_COMPR_PROTOCOL:
  84.             fprintf(fp,"VJ Compressed TCP/IP\n");
  85.             vjcomp_dump(fp,bpp,0);
  86.             break;
  87.         case PPP_UNCOMP_PROTOCOL:
  88.             fprintf(fp,"VJ Uncompressed TCP/IP\n");
  89.             /* Get our own copy so we can mess with the data */
  90.             if ( (tbp = copy_p(*bpp, len_p(*bpp))) == NULLBUF)
  91.                 return;
  92.  
  93.             fprintf(fp,"\tconnection 0x%02x\n",
  94.                 tbp->data[9]);        /* FIX THIS! */
  95.             /* Restore the bytes used with Uncompressed TCP */
  96.             tbp->data[9] = TCP_PTCL;    /* FIX THIS! */
  97.             ip_dump(fp,&tbp,1);
  98.             free_p(tbp);
  99.             break;
  100.         default:
  101.             fprintf(fp,"unknown 0x%04x\n",hdr.protocol);
  102.             break;
  103.     }
  104. }
  105.  
  106. #ifdef TURBOC_SWITCH_BUG
  107. #pragma option -G
  108. #endif
  109.  
  110. #endif /* PPP */
  111.  
  112.